//
//  ByCheckAccountVC.m
//  recordworktool_ios
//
//  Created by mc on 2017/12/9.
//  Copyright © 2017年 ZhangZhanbin. All rights reserved.
//

#import "ByCheckAccountVC.h"
#import "ByAccountHeadView.h"
#import "ByCheckAccountCell.h"
#import "ByAccountDetailVC.h"
@interface ByCheckAccountVC ()<UITableViewDelegate, UITableViewDataSource>



@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;


@end

@implementation ByCheckAccountVC

-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _dataArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addLeftBackBarButtonItem];
    self.title = @"核账";
    [self initViews];
    
   
    
    //下拉刷新数据
    ByCoreRefreshGifHeader *header = [ByCoreRefreshGifHeader headerWithRefreshingBlock:^{
        [self loadData];
    }];
    
    self.tableView.mj_header = header;
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
     [self loadData];
}
- (void)loadData{
    
    ByNetModel *netModel = [[ByNetModel alloc] init];
    netModel.uid = BY_USER.uid;
    netModel.mobile = BY_USER.mobile;
    [ByCoreToolAlert showLoadind:@"查询中"];
    
    if (BY_USER.isWorker.integerValue == 1) {
        [ByApiRecord queryAuditRecordForWorker:netModel success:^(ByNetBaseResult *result) {
            [self.tableView.mj_header endRefreshing];
            [ByCoreToolAlert hideHud];
            self.dataArray = result.data;
            [self.tableView reloadData];
            
        } failure:^(ByNetBaseResult *result) {
            [ByCoreToolAlert showFailureWithText:result.msg];
            [self.tableView.mj_header endRefreshing];
        }];
        
    }else{
        
        [ByApiRecord queryAuditRecordForOverseer:netModel success:^(ByNetBaseResult *result){
            [ByCoreToolAlert hideHud];
            self.dataArray = result.data;
            [self.tableView reloadData];
            [self.tableView.mj_header endRefreshing];
        } failure:^(ByNetBaseResult *result) {
            [self.tableView.mj_header endRefreshing];
            [ByCoreToolAlert showFailureWithText:result.msg];
        }];
    }
   
   
    
}



- (void)initViews{

    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT - STATUS_NAV) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];

}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ByNetModel *netModel = [self.dataArray objectAtIndex:indexPath.row];
    ByCheckAccountCell *cell = [ByCheckAccountCell cellWithTableView:tableView];
    cell.netModel = netModel;
    cell.detailAction = ^{
        NSLog(@"核账");
        ByAccountDetailVC *vc = [[ByAccountDetailVC alloc] init];
        vc.netModel = netModel;
        vc.type = 1;
        [self by_normalPush:vc hasNavi:YES];
    };
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 80;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    ByAccountHeadView *headView = [[ByAccountHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 80)];
    return headView;
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
